package compro.admission.form.email;

import compro.admission.form.entity.Application;
import compro.admission.form.entity.User;

public class SubmitApplicationEmail extends EmailTemplate {
	Email email;
	User user;
	Application application;

	public SubmitApplicationEmail(User user, Application application) {
		super(new Email());
		this.user = user;
		this.application = application;
		setEmailContent();
	}

	public Application getApplication() {
		return application;
	}

	public void setApplication(Application application) {
		this.application = application;
	}

	@Override
	public void setEmailContent() {
		String subject = "";
		String content = "";
		if (application.getDisposition().equals("undetermined")) {
			subject = "Please evaluate Application ID : " + application.getId();
		} else {
			subject = "Inform about Application ID : " + application.getId();
			subject += "Status : " + application.getDisposition();
		}

		super.getEmail().setToEmail(user.getEmail());
		super.getEmail().setSubject(subject);
		if (application.getDisposition().equals("undetermined"))
			content = setEmailUndertermined();
		else
			content = setEmailPassOrFail();

		super.getEmail().setMailText(content);

	}

	public String setEmailUndertermined() {

		User applicant = application.getUser();

		String content = "Hi Admission Staff,";
		content += "\n\n";
		content += "Please evaluate this following application :\n";
		content += "Name: " + applicant.getFirstname() + " "
				+ applicant.getLastname() + "\n";
		content += "Application ID: " + application.getId() + "\n";
		content += "Application Status: " + application.getDisposition()
				+ "\n\n";
		content += "Please click the link below to process:\n";
		content += "http://localhost:8989/comproAdmission/evaluateApplication?app_id=" + application.getId();
		content += "\n\n";
		content += "Best Regards,\n";
		content += "Admission Staff\n";
		content += "Maharishi University of Management";
		content += "\n\n";

		return content;
	}

	public String setEmailPassOrFail() {

		User applicant = application.getUser();

		String content = "Hi Admission Staff,";
		content += "\n\n";
		content += "Summary Information :\n";
		content += "Name: " + applicant.getFirstname() + " "
				+ applicant.getLastname() + "\n";
		content += "Application ID: " + application.getId() + "\n";
		content += "Application Status: " + application.getDisposition()
				+ "\n\n";
		content += "Best Regards,\n";
		content += "Admission Staff\n";
		content += "Maharishi University of Management";
		content += "\n\n";

		return content;
	}

}
